import Vue from 'vue'
function callback(el, val) {
    let count = val.value.count,
        number = val.value.number,
        key = val.value.key;
    if (key == count - 1) {
        let lack;
        if (number > count) {
            lack = number - count;
        } else if (count == number) {
            lack = 0;
        } else {
            if (count % number == 0){
                lack = 0
            }else{
                lack = number - (count % number);
            }
        }

        let listChildren = el.parentNode.children;

        for (var i = 0; i < listChildren.length; i++) {
            let string = new RegExp(/hidden/);
            if (string.test(listChildren[i].className)) {
                let childrenNode = listChildren[i];
                el.parentNode.removeChild(childrenNode);
                i--;
            }
        }
        for (var i = 0; i < lack; i++) {
            let els = el.cloneNode(true);
            els.classList.add("hidden");
            els.style.visibility = "hidden";
            els.style.opacity = 0;
            el.parentNode.appendChild(els);
        }
    }
}
Vue.directive('flex_for', {
    inserted: function (el, val) {
        callback(el,val)
    },
    update: function (el, val) {
        callback(el,val)
    },
})
/*
添加for循环下的子节点  防止flex出现子节点布局失效
val:{count:列表总数, number:  每行个数 , key :循环的key值 }

*/